package cn.hairui.blog.mapper;

import cn.hairui.blog.model.TabMenu;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.BaseMapper;

import java.util.List;
import java.util.Map;

/**
 * @author lihairui
 * @version V1.0
 * @date: 2019/7/28 19:37
 */
@Mapper
public interface TabMenuMapper extends BaseMapper<TabMenu> {

    @Select("SELECT * FROM TAB_MENU ORDER BY ID ASC")
    List<TabMenu> list();

    @Select("SELECT t1.ID as id,t1.NAME as name,CASE WHEN t1.SHOW_HOMEPAGE='Y' THEN 'checked' ELSE '' END AS showHomepage,(select count(1) from artical t2 where t1.id=t2.NAVID)  as articalNum FROM TAB_MENU t1 ORDER BY t1.ID ASC")
    List<Map> listMgr();

    @Update("UPDATE TAB_MENU SET SHOW_HOMEPAGE=#{flag} WHERE ID=#{id}")
    void updateShowFlag(int id, String flag);

    @Select("SELECT * FROM TAB_MENU WHERE ID=#{pk}")
    TabMenu find(int pk);

    @Select("SELECT * FROM TAB_MENU WHERE SHOW_HOMEPAGE='Y'")
    List<TabMenu> listShow();

    @Update("UPDATE TAB_MENU SET NAME=#{name},SHOW_HOMEPAGE=#{showHomepage} WHERE ID=#{id}")
    int update(TabMenu tabMenu);

    @Delete("DELETE FROM TAB_MENU WHERE ID=#{id}")
    int deletebyPk(int id);
}
